﻿using DotNetCore.CAP;
using MyTask.Domain;
using MyTask.Tasking.Applicaiton.IntegrationEvents;
using MyTask.Tasking.Domain.Events;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace MyTask.Tasking.Applicaiton.DomainEventHandlers
{
    public class TaskCreatedDomainEventHandler : IDomainEventHandler<TaskCreatedDomainEvent>
    {
        ICapPublisher _capPublisher;
        public TaskCreatedDomainEventHandler(ICapPublisher capPublisher)
        {
            _capPublisher = capPublisher;
        }
        public async Task Handle(TaskCreatedDomainEvent notification, CancellationToken cancellationToken)
        {
            await _capPublisher.PublishAsync("TaskCreated", new TaskCreatedIntegrationEvent(notification.TaskInfo.Id));
        }
    }
}
